package biz.impl;

import java.util.List;

import biz.DriverBiz;
import dao.DriverDao;
import dao.OrderDao;
import dao.impl.DriverDaoImpl;
import dao.impl.OrderDaoImpl;
import entity.Driver;

public class DriverBizImpl implements DriverBiz {
	DriverDao driverDao = new DriverDaoImpl();
	OrderDao orderDao = new OrderDaoImpl();
	
	@Override
	public Driver loginDriver(String userName, String password) {
		Driver driver = driverDao.queryDriver(userName, password);
		if(driver!=null){
			driver.setOrderList(orderDao.queryOrderByDriverId(driver.getDriverId()));
		}
		return driver;
	}

	@Override
	public Driver DriverQueryOrderInfo(int driverId) {
		Driver driver =driverDao.queryDriverByDriverId(driverId);
		if(driver!=null){
			driver.setOrderList(orderDao.queryOrderByDriverId(driverId));
		}
		return driver;
	}

	@Override
	public List<Driver> queryAllDriver() {
		List<Driver> driverList = driverDao.queryAllDriver();
		for (Driver driver : driverList) {
			if(driver!=null){
				driver.setOrderList(orderDao.queryOrderByDriverId(driver.getDriverId()));
			}
		}
		return driverList;
	}

}
